package leetcode;

public class C12006 {
    public static void main(String[] args) {
        int[][] a = new int[][]{{13, 22, 17}, {12, 16, 20}, {14, 13, 29},};
        int m=3,n=3;
        int i,j,l;
        int max=0;
        for(i=1;i<n;i++){
            for(j=0;j<m;j++) {
                if(j!=m-1){
                    max=a[i-1][m-1];
                }else{
                    max=a[i-1][0];
                }

                for(l=0;l<m;l++){
                    if(j!=l){
                        if(max<a[i-1][l]){
                            max=a[i-1][l];
                        }
                    }
                    else{
                        max=max;
                    }
                }
                a[i][j]=a[i][j]+max;

            }
        }
         max=a[n-1][0];
        for(j=0;j<m;j++){
           if(max<a[n-1][j]){
               max=a[n-1][j];
           }
        }

            System.out.println(max);



    }
}
